<?php

use App\Api\Controllers\Backend\AdminUsersController;
use App\Api\Controllers\Backend\ApplyController;
use App\Api\Controllers\Backend\ManageController;
use App\Api\Controllers\Common\CommonController;
use App\Api\Controllers\Interview\UserInterviewController;

// Dingo 的 Api 路由
$api = app(Dingo\Api\Routing\Router::class);
$api->version('v1', function ($api) {
    // 面试模块
    $api->group(['prefix' => 'external', 'middleware' => 'swoolerequests'], function ($api) {
        $api->any('user/{func}', UserInterviewController::class . '@interview');

        // 面试信息相关
        $api->any('interview', UserInterviewController::class . '@interview');
        $api->group(['middleware' => ['auth:interview', 'jwt.role:interview']], function ($api) {
            //填写面试表单后续
            $api->any('interview/{func}', UserInterviewController::class . '@interview');
        });
    });
    // 操作端
    $api->group(['prefix' => 'back', 'middleware' => 'swoolerequests'], function ($api) {

        $api->group(['middleware' => ['auth:api', 'jwt.role:user']], function ($api) {
            // 面试管理模块
            $api->any('interview', ManageController::class . '@interviewManage');
            $api->any('interview/{func}', ManageController::class . '@interviewManage');
            // 面试题管理
            $api->any('exam', ManageController::class . '@examManage');
            $api->any('exam/{func}', ManageController::class . '@examManage');
            // 员工管理
            $api->group(['prefix' => 'staff'], function ($api) {
                $api->any('{func}', ManageController::class . '@staffManage');
                $api->any('department/{func}', ManageController::class . '@department');
            });
            // 代办事宜
            $api->group(['prefix' => 'commission'], function ($api) {
                $api->any('{func}', ManageController::class . '@commissionManage');
            });
            // 职称
            $api->group(['prefix' => 'position'], function ($api) {
                $api->any('{func}', ManageController::class . '@positionManage');
            });
            // 系统设置
            $api->group(['prefix' => 'system'], function ($api) {
                $api->any('{func}', ManageController::class . '@systemManage');
            });
            // 申请模块
            $api->group(['prefix' => 'apply'], function ($api) {
                // 请假申请
                $api->any('/askleave/{func}', ApplyController::class . '@askLeave');
                // 外出/出差  申请
                $api->any('/evection/{func}', ApplyController::class . '@evection');
                // 报销申请
                $api->any('/expense/{func}', ApplyController::class . '@expense');
                // 备用金申请
                $api->any('/imprest/{func}', ApplyController::class . '@imprest');
                // 用章申请
                $api->any('/signet/{func}', ApplyController::class . '@signet');
                // 付款申请
                $api->any('/payment/{func}', ApplyController::class . '@payment');
            });
            // 个人数据操作
            $api->any('user/{func}', ManageController::class . '@userhandle');
            // 绩效数据
            $api->any('performance/{func}', ManageController::class . '@performance');
            // 公共参数
            $api->any('common/{func}', ManageController::class . '@common');
        });
        // 登录
        $api->post('login', AdminUsersController::class . '@login');
        $api->post('automatic', AdminUsersController::class . '@automatic');
    });
    // 公共
    $api->group(['prefix' => 'common', 'middleware' => 'swoolerequests'], function ($api) {
        // 获取短信验证码
        $api->post('captcha', CommonController::class . '@captcha');
        $api->group(['middleware' => ['auth:api', 'jwt.role:user']], function ($api) {
            $api->match(['get', 'post'], 'upload', CommonController::class . '@upload');
        });
        $api->group(['middleware' => ['auth:interview', 'jwt.role:interview']], function ($api) {
            $api->match(['get', 'post'], 'upload_back', CommonController::class . '@upload');
            $api->match(['get', 'post'], 'ceshi', CommonController::class . '@ceshi');
        });
    });
});
